// frontendMenu.ts
import { LogicalPosition } from '@tauri-apps/api/window';
import { Menu } from '@tauri-apps/api/menu';
import { controlWindow } from './window';
import BoardChannel from './boardChannel';

(async () => {
    const channel = new BoardChannel('bp-system');
    const menu = await Menu.new({
        items: [
            {
                id: 'hide-map',
                text: '隐藏窗口',
                action: async () => {
                    channel.send('hideWindow', 'bp-map');
                    await controlWindow('bp-map', 'hide');
                },
            },
        ],
    });

    await menu.setAsAppMenu();
    window.addEventListener('contextmenu', async (event) => {
        event.preventDefault();
        menu.popup(new LogicalPosition(event.clientX, event.clientY));
    });
})();